/** 
 * @author Huynh 
 * Last modified by: Huynh.
 */
package controller;

import android.app.Activity;
import android.content.Intent;
import android.fourrows.R;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FourRows extends Activity implements OnClickListener {
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.main);
		Log.i("FourRows", "FourRows activity started");

		Button vsHuman = (Button) findViewById(R.id.vs_human);
		vsHuman.setOnClickListener(this);

		Button vsComputer = (Button) findViewById(R.id.vs_computer);
		vsComputer.setOnClickListener(this);

		Button computerVshuman = (Button) findViewById(R.id.computer_vs_human);
		computerVshuman.setOnClickListener(this);

		Button aboutButton = (Button) findViewById(R.id.about_button);
		aboutButton.setOnClickListener(this);

		Button loadGameButton = (Button) findViewById(R.id.load_game_button);
		loadGameButton.setOnClickListener(this);

		Button helpButton = (Button) findViewById(R.id.help_button);
		helpButton.setOnClickListener(this);

		Button quitButton = (Button) findViewById(R.id.quit_button);
		quitButton.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		int gameType = -1;

		switch (v.getId()) {
		case R.id.quit_button:
			finish();
			break;

		case R.id.about_button:
			Intent aboutIntent = new Intent(this, About.class);
			startActivity(aboutIntent);
			break;
		case R.id.help_button:
			Intent help = new Intent(this, Help.class);
			startActivity(help);
			break;
		case R.id.vs_human:
			gameType = Constant.HUMAN_VS_HUMAN;
			break;
		case R.id.vs_computer:
			gameType = Constant.HUMAN_VS_COMP;
			break;
		case R.id.computer_vs_human:
			gameType = Constant.COMP_VS_HUMAN;
			break;
		case R.id.load_game_button:
			Intent loadGame = new Intent(this, LoadGame.class);
			startActivity(loadGame);
			break;
		default:
			break;
		}

		// If this is an off-line game, start it now.
		if (gameType == Constant.COMP_VS_HUMAN
				|| gameType == Constant.HUMAN_VS_COMP
				|| gameType == Constant.HUMAN_VS_HUMAN) {
			Log.i("onClickListener", "game type: " + gameType);
			Intent game = new Intent(this, GameDisplay.class);
			game.putExtra("game_type", gameType);
			startActivity(game);
		}
	}
}